package com.newland.mesdk.demo.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RadioButton;

import com.newland.mesdk.demo.main.R;
import com.newland.mesdk.demo.main.MainActivity;
import com.newland.mesdk.demo.util.Const;
import com.newland.mesdk.demo.util.SharedPreferencesUtil;

/**
 * Created by YJF 子菜单选择项卡
 */
public class ChildMenuFragment extends Fragment implements OnClickListener {
	private int checkedModule;
	private MainActivity mainActivity;
	private String deviceType;
	private RadioButton radBtnTernaml, radBtnBuzzer, radBtnCardReader, radBtnEMV;
	private RadioButton radBtnLCD, radBtnICCARD, radBtnLight, radBtnConsume;
	private RadioButton radBtnKeyboard, radBtnPin, radBtnPrinter, radBtnQpboc, radBtnSwip;
	private RadioButton radBtnRFCard, radBtnExternalPin, radBtnSecurity, radBtnScanner, radioBtnStorage;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_childmenu, null);
		mainActivity = (MainActivity) getActivity();
		deviceType = SharedPreferencesUtil.getStringParam(view.getContext(), Const.DEVICETYPE);
		checkedModule = SharedPreferencesUtil.getIntParam(view.getContext(), Const.CHECK_MODULE);

		initChildMemuBtn(view);
		initChildMenuView();

		return view;
	}

	public void initChildMemuBtn(View view) {
		radBtnTernaml = (RadioButton) view.findViewById(R.id.radiobtn_ternalmanage);
		radBtnTernaml.setOnClickListener(this);

		radBtnBuzzer = (RadioButton) view.findViewById(R.id.radiobtn_buzzer);
		radBtnBuzzer.setOnClickListener(this);

		radBtnCardReader = (RadioButton) view.findViewById(R.id.radiobtn_cardreader);
		radBtnCardReader.setOnClickListener(this);

		radBtnEMV = (RadioButton) view.findViewById(R.id.radiobtn_emv);
		radBtnEMV.setOnClickListener(this);

		radBtnLCD = (RadioButton) view.findViewById(R.id.radiobtn_lcd);
		radBtnLCD.setOnClickListener(this);

		radBtnICCARD = (RadioButton) view.findViewById(R.id.radiobtn_iccard);
		radBtnICCARD.setOnClickListener(this);

		radBtnLight = (RadioButton) view.findViewById(R.id.radiobtn_light);
		radBtnLight.setOnClickListener(this);

		radBtnConsume = (RadioButton) view.findViewById(R.id.radiobtn_consume);
		radBtnConsume.setOnClickListener(this);

		radBtnKeyboard = (RadioButton) view.findViewById(R.id.radiobtn_keyboard);
		radBtnKeyboard.setOnClickListener(this);

		radBtnPin = (RadioButton) view.findViewById(R.id.radiobtn_pin);
		radBtnPin.setOnClickListener(this);

		radBtnPrinter = (RadioButton) view.findViewById(R.id.radiobtn_printer);
		radBtnPrinter.setOnClickListener(this);

		radBtnQpboc = (RadioButton) view.findViewById(R.id.radiobtn_qpboc);
		radBtnQpboc.setOnClickListener(this);

		radBtnRFCard = (RadioButton) view.findViewById(R.id.radiobtn_rfcard);
		radBtnRFCard.setOnClickListener(this);

		radBtnSecurity = (RadioButton) view.findViewById(R.id.radiobtn_security);
		radBtnSecurity.setOnClickListener(this);

		radBtnScanner = (RadioButton) view.findViewById(R.id.radiobtn_scanner);
		radBtnScanner.setOnClickListener(this);

		radBtnExternalPin = (RadioButton) view.findViewById(R.id.radiobtn_external_pin);
		radBtnExternalPin.setOnClickListener(this);

		radBtnSwip = (RadioButton) view.findViewById(R.id.radiobtn_swip);
		radBtnSwip.setOnClickListener(this);

		radioBtnStorage = (RadioButton) view.findViewById(R.id.radiobtn_storage);
		radioBtnStorage.setOnClickListener(this);

		if (deviceType.equals(Const.DeviceName.ME30)) {
			radBtnBuzzer.setVisibility(View.GONE);
			radBtnLight.setVisibility(View.GONE);
			radBtnScanner.setVisibility(View.GONE);
			radBtnExternalPin.setVisibility(View.GONE);
			radBtnPrinter.setVisibility(View.GONE);
		} else if (deviceType.equals(Const.DeviceName.ME31)) {
			radBtnBuzzer.setVisibility(View.GONE);
			radBtnLight.setVisibility(View.GONE);
			radBtnScanner.setVisibility(View.GONE);
			radBtnExternalPin.setVisibility(View.GONE);
		} else if (deviceType.equals(Const.DeviceName.IM81)) {
			radBtnLCD.setVisibility(View.GONE);
			radBtnScanner.setVisibility(View.GONE);
			radBtnQpboc.setVisibility(View.GONE);
		} else if (deviceType.equals(Const.DeviceName.N900)) {
			radBtnBuzzer.setVisibility(View.GONE);
			radBtnExternalPin.setVisibility(View.GONE);
			radBtnLCD.setVisibility(View.GONE);
			radBtnQpboc.setVisibility(View.GONE);
			radBtnKeyboard.setVisibility(View.GONE);
		} else if (deviceType.equals(Const.DeviceName.AUDIO)) {
			radBtnBuzzer.setVisibility(View.GONE);
			radBtnExternalPin.setVisibility(View.GONE);
			radBtnLCD.setVisibility(View.GONE);
			radBtnQpboc.setVisibility(View.GONE);
			radBtnPrinter.setVisibility(View.GONE);
			radBtnScanner.setVisibility(View.GONE);
			radBtnLight.setVisibility(View.GONE);
			radBtnKeyboard.setVisibility(View.GONE);
			radBtnSwip.setVisibility(View.GONE);
			radBtnRFCard.setVisibility(View.GONE);
		}
	}

	// 初始化子菜单，确定选中的模块
	public void initChildMenuView() {
		switch (checkedModule) {
		case Const.CheckedModuleName.TERNAL:
			radBtnTernaml.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new TerminalManageFragment());
			break;
		case Const.CheckedModuleName.BUZZER:
			radBtnBuzzer.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new BuzzerFragment());
			break;
		case Const.CheckedModuleName.CARDREADER:
			radBtnCardReader.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new CardReaderFragment());
			break;
		case Const.CheckedModuleName.EMV:
			radBtnEMV.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new EMVFragment());
			break;
		case Const.CheckedModuleName.LCD:
			radBtnLCD.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new LCDFragment());
			break;
		case Const.CheckedModuleName.ICCARD:
			radBtnICCARD.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new ICCardFragment());
			break;
		case Const.CheckedModuleName.LIGHT:
			radBtnLight.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new LightFragment());
			break;
		case Const.CheckedModuleName.CONSUME:
			radBtnConsume.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new ConsumeFragment());
			break;
		case Const.CheckedModuleName.KEYBOARD:
			radBtnKeyboard.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new KeyBoardFragment());
			break;
		case Const.CheckedModuleName.PIN:
			radBtnPin.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new PinFragment());
			break;
		case Const.CheckedModuleName.PRINTER:
			radBtnPrinter.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new PrinterFragment());
			break;
		case Const.CheckedModuleName.QPOBC:
			radBtnQpboc.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new QPBOCFragment());
			break;
		case Const.CheckedModuleName.RFCARD:
			radBtnRFCard.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new RFCardFragment());
			break;
		case Const.CheckedModuleName.SECURITY:
			radBtnSecurity.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new SecurityFragment());
			break;
		case Const.CheckedModuleName.SCANNER:
			radBtnScanner.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new Scannerfragment());
			break;

		case Const.CheckedModuleName.SWIP:
			radBtnSwip.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new SwipFragment());
			break;
		case Const.CheckedModuleName.EXTERNALPIN:
			radBtnExternalPin.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new ExternalPinInputFragment());
			break;
		case Const.CheckedModuleName.STORAGE:
			radioBtnStorage.setChecked(true);
			mainActivity.switchFragment(R.id.frame_childmenu, new StorgaeFragment());
			break;

		default:
			break;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.radiobtn_ternalmanage: {
			mainActivity.switchFragment(R.id.frame_childmenu, new TerminalManageFragment());
			break;
		}
		case R.id.radiobtn_buzzer: {
			mainActivity.switchFragment(R.id.frame_childmenu, new BuzzerFragment());
			break;
		}
		case R.id.radiobtn_cardreader: {
			mainActivity.switchFragment(R.id.frame_childmenu, new CardReaderFragment());
			break;
		}
		case R.id.radiobtn_consume: {
			mainActivity.switchFragment(R.id.frame_childmenu, new ConsumeFragment());
			break;
		}
		case R.id.radiobtn_emv: {
			mainActivity.switchFragment(R.id.frame_childmenu, new EMVFragment());
			break;
		}
		case R.id.radiobtn_iccard: {
			mainActivity.switchFragment(R.id.frame_childmenu, new ICCardFragment());
			break;
		}
		case R.id.radiobtn_light: {
			mainActivity.switchFragment(R.id.frame_childmenu, new LightFragment());
			break;
		}
		case R.id.radiobtn_keyboard: {
			mainActivity.switchFragment(R.id.frame_childmenu, new KeyBoardFragment());
			break;
		}
		case R.id.radiobtn_pin: {
			mainActivity.switchFragment(R.id.frame_childmenu, new PinFragment());
			break;
		}
		case R.id.radiobtn_printer: {
			mainActivity.switchFragment(R.id.frame_childmenu, new PrinterFragment());
			break;
		}
		case R.id.radiobtn_qpboc: {
			mainActivity.switchFragment(R.id.frame_childmenu, new QPBOCFragment());
			break;
		}
		case R.id.radiobtn_rfcard: {
			mainActivity.switchFragment(R.id.frame_childmenu, new RFCardFragment());
			break;
		}
		case R.id.radiobtn_security: {
			mainActivity.switchFragment(R.id.frame_childmenu, new SecurityFragment());
			break;
		}
		case R.id.radiobtn_scanner: {
			mainActivity.switchFragment(R.id.frame_childmenu, new Scannerfragment());
			break;
		}
		case R.id.radiobtn_external_pin: {
			mainActivity.switchFragment(R.id.frame_childmenu, new ExternalPinInputFragment());
			break;
		}
		case R.id.radiobtn_swip: {
			mainActivity.switchFragment(R.id.frame_childmenu, new SwipFragment());
			break;
		}
		case R.id.radiobtn_lcd: {
			mainActivity.switchFragment(R.id.frame_childmenu, new LCDFragment());
			break;
		}
		case R.id.radiobtn_storage: {
			mainActivity.switchFragment(R.id.frame_childmenu, new StorgaeFragment());
			break;
		}

		default: {
			break;
		}

		}
	}
}
